package data_structure

import scala.collection.mutable.Map

// Iterator，迭代器提供了按顺序访问容器元素功能的数据结构
// 迭代器不是容器类，不能随机访问迭代器的元素，只能按从前往后的顺序依次访问其元素
// 迭代器常用于需要对容器进行一次遍历的场景
object TestIterator {
  def main(args: Array[String]): Unit = {
    val iter = Iterator("Hadoop", "Spark", "Scala")
    while (iter.hasNext) {
      println(iter.next())
    }

    val items = Array("Monday", "Tuesday", "Friday")
    val itemsIter = items.iterator
    while (itemsIter.hasNext) {
      println(itemsIter.next())
    }

    val university = Map("XMU" -> "Xiamen University", "THU" -> "Tsinghua University", "PKU" -> "Peking University")
    val universityIter = university.iterator
    while (universityIter.hasNext) {
      println(universityIter.next())
    }
  }
}
